home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Cinema 4D GO demo / Gumption Plug-ins / Plug-ins / Freeware / Path2Spline / path2spl.cof < prev    next >
Text File  |  1998-06-16  |  3KB  |  114 lines

  1. // Konversion von objektpositionen zu einem spline
  2. //
  3. // Motion Gimmick
  4. //
  5. // Autor: Roland Fietkau
  6. //
  7. class Tuserinput
  8. {
  9.      public:
  10.      var close;
  11.      var framestart,frameend;
  12.      var name;
  13.      var tangents;
  14.      var cancelled;
  15. }
  16.  
  17.  
  18. HandleUserDialog(objname,s,e)
  19. {
  20.    var ui=new(Tuserinput);
  21.    // defaultwerte
  22.    ui->close=FALSE;
  23.    ui->tangents=TRUE;
  24.    ui->framestart=s;
  25.    ui->frameend=e;
  26.    ui->name="path";
  27.    ui->cancelled=FALSE;
  28.    
  29.            var sd=new(SimpleDialog);
  30.            var z1=stradd("Path from: ",objname);
  31.            sd->SetTitle(z1);
  32.            sd->SetData(0,"First Frame",FIELD_INTEGER,s,e,ui->framestart);
  33.            sd->SetData(5,"Last  Frame",FIELD_INTEGER,s,e,ui->frameend);
  34.            sd->SetData(1,"Close Spline? ",FIELD_STRING,0,0,"No");
  35.            sd->SetData(2,"Name ",FIELD_STRING,0,0,"path");
  36.            sd->SetData(6,"Set Tangents?",FIELD_STRING,0,0,"Yes");    
  37.            
  38.            if (sd->DoDialog())
  39.            {
  40.                ui->framestart=sd->GetData(0); 
  41.                ui->frameend=sd->GetData(5);   
  42.                ui->name=sd->GetData(2);
  43.                ui->close= !(0 == strcmp(sd->GetData(1),"No"));               
  44.                ui->tangents= (0 == strcmp(sd->GetData(6),"Yes"));               
  45.            }
  46.            else
  47.            {
  48.                ui->cancelled=TRUE;
  49.            }; 
  50.    return(ui);
  51. }
  52.  
  53.  
  54. mymain(doc)
  55. {
  56.         var obj1=doc->FindFirstActiveObject();
  57.         if ((!obj1) )
  58.         {        
  59.            TextDialog( "Need activated Object",DLG_OK+DLG_ICONEXCLAMATION);
  60.            TextDialog( "Don¥t try that again!",DLG_OK+DLG_ICONEXCLAMATION);
  61.         }else
  62.         {   //wir haben aktiviertes objekt
  63.             
  64.             var ui=HandleUserDialog(obj1->GetName(),0,int(doc->GetMaxTime()*doc->GetFps()));
  65.  
  66.          if (!ui->cancelled)
  67.          {        
  68.  
  69.             var splpointcount=1 + abs( ui->frameend - ui->framestart);
  70.             var nspl=doc->NewSplineObject(ui->name,NULL,NULL,splpointcount);
  71.             var nsplinfo=new(SplineInfo);
  72.             nsplinfo->number=5; 
  73.             nsplinfo->inter=0;  
  74.             nsplinfo->closed=ui->close ;
  75.             nsplinfo->type=SPL_HERMITE ; 
  76.             
  77.             nspl->SetSplineInfo(nsplinfo);
  78.             //und los    
  79.  
  80.             var t=float(ui->framestart) / doc->GetFps();
  81.             var dt= ( (ui->frameend>=ui->framestart)? 1.0 : -1.0) /doc->GetFps();
  82.             var k=0;            
  83.             var mmm=new(Matrix);
  84.  
  85.             for (;  (k<splpointcount) ;  t+=dt,k+=1)
  86.             {
  87.                doc->SetTime(t,41);  //41 ist meine Schuhgroesse               
  88.                obj1->GetUpMg(mmm);
  89.                var ppkt=obj1->GetPosition();
  90.                ppkt=mmm->MulP(ppkt);
  91.                nspl->SetPoint(k,ppkt,vector(0),vector(0));    
  92.             };         
  93.  
  94.             if (ui->tangents)  
  95.             { 
  96.                doc->ActivateObject(nspl);      //Aktivieren sonst ...
  97.                nspl->SetDefaultTangents(TRUE); //... hier uebler Absturz
  98.             };
  99.             nspl->UpdateObject();
  100.             doc->SendMessage(DOCUMENT_CHANGED);
  101.             doc->SendMessage(REDRAW_ALL);
  102.          }
  103.  
  104.  
  105.         };    
  106.  
  107. }
  108.  
  109.  
  110. main()
  111.         RegisterMenuHook("Path_2_Spl","mymain");
  112. };
  113.